<?php
class Default_Model_DbTable_RecipeHasThemes extends Default_Model_DbTable_DbTableEntityAbstract
{
	protected $_db;
	protected $_primary = 'recipe_id';
	//protected $_dependentTables = array('Default_Model_DbTable_FoodTypes');
	
    public function init()
    {
    	$this->_db = Zend_Db_Table::getDefaultAdapter();
    	$this->_name = 'themes_has_recipes';
    }
    
    public function addThemeRecipes($data)
    {
    	if( $this->insert($data) ){
    		return true;
    	}
    }
    
    public function getRecipesByThemeId($themeId)
    {
    	$select = $this->_db->select()
    				   ->from(array('thr' => 'themes_has_recipes'))
    				   ->join(
    				       array('t' => 'themes'),
    				       't.theme_id = thr.theme_id'
    				   )
    	               ->where("thr.theme_id = ?", $themeId);
    	$result = $this->_db->fetchAll($select);
    	
    	//var_dump($select->__toString());
    	return $result;
    }
    
	public function deleteRecipeFromTheme($recipeId)
    {
    	$where = $this->getAdapter()->quoteInto('recipe_id = ?', $recipeId);
		$this->delete($where);
    }
    
    public function getRecipeThemes($recipeId)
    {
    	$select = $this->select()
    				   ->from($this, array('theme_id'))
    	               ->where("recipe_id = ?", $recipeId);
    	$result = $this->fetchAll($select);
    	return $result;
    }
}